package logic

import (
	"camera/C/Rpc/model/mysql"
	"context"
	"fmt"

	"camera/C/Rpc/camera"
	"camera/C/Rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *ShowLogic) Show(in *camera.ShowRequest) (*camera.ShowResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{}
	good, err := g.ShowGood(int(in.GoodId))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	var show []*camera.Show
	for _, g2 := range good {
		show = append(show, &camera.Show{
			UserId:    int64(g2.UserId),
			GoodTitle: g2.GoodTitle,
			GoodStock: int64(g2.GoodStock),
			GoodImage: g2.GoodImage,
			GoodPrice: float32(g2.GoodPrice),
			GoodLike:  int64(g2.GoodLike),
			Id:        int64(g2.ID),
		})
	}
	return &camera.ShowResponse{
		Show: show,
	}, nil
}
